package com.wfms.service;

import com.wfms.bean.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;


/**
 * Created by Administrator on 2017/12/25.
 * feign注解集成 hystrx
 */
@FeignClient(value = "eurekaClient",/** fallback =UserServiceHystrxImpl.class **/ fallbackFactory= FallbackUserServiceHystrx.class)
public interface UserServiceHystrx {


    @GetMapping("/eureka/user/{id}")
    public User findById(@PathVariable("id")int id);

}
@Component
 class FallbackUserServiceHystrx implements FallbackFactory<UserServiceHystrx>{

    private static final Logger logger = LoggerFactory.getLogger(FallbackUserServiceHystrx.class);
    @Override
    public UserServiceHystrx create(Throwable throwable) {
        logger.info(throwable.getMessage());

        return new UserServiceHystrx() {
            @Override
            public User findById(int id) {
                return new User("error",4444);
            }
        };
    }
}


